<?php
$id = $_REQUEST["id"];
$xuehao = $_REQUEST["xuehao"];
$kcbianhao = $_REQUEST["kcbianhao"];
$chengji = $_REQUEST["chengji"];
$action = $_REQUEST["action"];
echo "$xuehao";
echo "$kcbianhao";
echo "$chengji";

include_once("conn.php");
//3.运行sql语句，执行增、删、改、查
if($action=="add"){
    $sql1 = "insert into `选修`(学号,课程编号,成绩)value('{$xuehao}','{$kcbianhao}','{$chengji}')";
    $str = "数据插入成功！";
}else if($action=="update"){
    $sql1 = "update 选修 set 学号='{$xuehao}',课程编号='{$kcbianhao}',成绩='{$chengji}' where id='{$id}'";
    $str = "数据修改成功！";
}else{
    die("请正确输入参数");
}
$result = mysqli_query($conn,$sql1);
if($result){
    echo "<script>alert('{$str}')</script>";
    header("Refresh:1;url=chengji-list.php");
}else{
    echo "<script>alert('数据插入失败')</script>";
}
//4.关闭连接，释放资源
mysqli_close($conn);

?>